import axios from 'axios'
import md5 from 'js-md5'

export function doLogin (usr, pwd) {
  const option = {
    user: usr,
    pass: md5(pwd)
  }

  return axios({
    method: 'post',
    url: '/api/login',
    header: { 'Content-Type': 'application/json' },
    data: option
  })
}

export function doCommitQuestnaire (type, group, unit, answers, questuser) {
  const option = {
    type: type,
    group: group,
    unit: unit,
    answers: answers,
    questuser: questuser
  }

  return axios({
    method: 'post',
    url: '/api/postquestionnaire',
    header: { 'Content-Type': 'application/json' },
    data: option
  })
}

export function getQuestnaire (type, group, unit) {
  const option = {
    type: type,
    group: group,
    unit: unit
  }

  return axios({
    method: 'get',
    url: '/api/questionnaire',
    header: { 'Content-Type': 'application/json' },
    params: option
  })
}

export function uploadImages (formdata) {
  const option = {
    formdata: formdata
  }
  return axios({
    method: 'post',
    url: '/api/uploadfiles',
    data: option
  })
}

export function getImages (filelist) {
  const option = {
    fileids: filelist.join(',')
  }
  return axios({
    method: 'post',
    url: '/api/getFileList',
    header: { 'Content-Type': 'application/json' },
    data: option
  })
}
